﻿#include "CCamerCtrMange.h"
#include "CHeader.h"
#include "CLogOper.h"
#include "CPolArea.h"
#include <qeventloop.h>
#include <qthread.h>
#include "CPublicData.h"

CCamerCtrMange::CCamerCtrMange(CDevDataBase * pDevData)
{
	m_pDevData = pDevData;
	m_pDevDataCam = m_pDevData->m_pDevDataCam;
	m_pCamerSdkOper = new CCamerSdkOperEx(m_pDevDataCam);
	m_pMutex = new QMutex(QMutex::Recursive);
	m_pThread = new QThread();
	connect(m_pThread, SIGNAL(started()), this, SLOT(slot_ThreadWork()));
	this->moveToThread(m_pThread);
	m_bhread = false;
}

CCamerCtrMange::~CCamerCtrMange()
{
	ThreadStop();
	if (m_pCamerSdkOper)
	{
		delete m_pCamerSdkOper;
		m_pCamerSdkOper = nullptr;
	}
	if (m_pThread != nullptr)
	{
		delete m_pThread;
		m_pThread = nullptr;
	}

	if (m_pMutex != nullptr)
	{
		delete m_pMutex;
		m_pMutex = nullptr;
	}
}

void CCamerCtrMange::ThreadStart()
{
	m_pThread->start();
}

void CCamerCtrMange::ThreadStop()
{
	m_bhread = false;
	m_pThread->quit();
	if (!m_pThread->wait(5000))
	{
		m_pThread->terminate();
	}
}

bool CCamerCtrMange::ctrDevice(SCtrInfo &stCtrInfo)//Modifywxy 改成引用
{
	if (stCtrInfo.m_bCtrSync == true)
	{
		return ctrDeviceMy(stCtrInfo);
	}
	else
	{
		//如果线程没启动 开启线程
		if (!m_bhread)
			ThreadStart();
		if (m_pMutex->tryLock(3000))
		{
			if (m_vecCtrQueue.size() > 5)
				m_vecCtrQueue.clear();
			//如果是重复命令不添加
			if (m_vecCtrQueue.size() >= 1)
			{
				SCtrInfo stCtrInfoLast = m_vecCtrQueue[m_vecCtrQueue.size() - 1];
				if (stCtrInfo.m_nCtrCmd != stCtrInfoLast.m_nCtrCmd || stCtrInfo.m_nSubCtrDevType != stCtrInfoLast.m_nSubCtrDevType)
				{
					m_vecCtrQueue.push_back(stCtrInfo);
				}
			}
			else
			{
				m_vecCtrQueue.push_back(stCtrInfo);
			}
			m_pMutex->unlock();
			return true;
		}
		else
		{
			return false;
		}
	}
}

bool CCamerCtrMange::ctrDeviceEx(SCtrInfo stCtrInfo)
{
	if (stCtrInfo.m_bHasCtr)
	{
		if (m_pDevData->getDevCtr(stCtrInfo.m_sGuid))
		{
			return ctrDevice(stCtrInfo);
		}
		else
		{
			bool bResult = true;
			SDevExecLog sDevExecLog;
			sDevExecLog.m_sDevName = A2T("云台");
			sDevExecLog.m_nAlarmLevel = enWorkInfo;
			sDevExecLog.m_sDescriptionl = A2T("当前对象没有获取到控制权限");
			sDevExecLog.m_bExecResult = false;
			stCtrInfo.m_sReData = A2T("当前对象没有获取到控制权限");
			m_pDevData->addDevExecLog(sDevExecLog);
			return false;
		}
	}
	else
	{
		//设备本体
		return ctrDevice(stCtrInfo);
	}
}

bool CCamerCtrMange::ctrDeviceMy(SCtrInfo &stCtrInfo)//Modifywxy 改成引用
{
	SCtrReData cCtrReData;
	cCtrReData.nCtrType = stCtrInfo.m_nCtrCmd;
	int nCmd = stCtrInfo.m_nCtrCmd;
	bool bResult = true;
	switch (nCmd)
	{
	case enCNoCmd:
		bResult = true;
		break;
	case enCLogin:
		bResult = login(stCtrInfo);
		break;
	case enCRealPlay:
		bResult = realPlay(stCtrInfo);
		break;
	case enCStopRealPlay:
		bResult = stopRealPlay(stCtrInfo);
		break;
	case enCCapture:
		bResult = capture(stCtrInfo);
		break;
	case enCRecord:
		bResult = recordVideo(stCtrInfo);
		break;
	case enCStopRecord:
		bResult = stopRecordVideo(stCtrInfo);
		break;
	case enCVoiceTalk:
		bResult = startVoiceTalk(stCtrInfo);
		break;
	case enCStopVoiceTalk:
		bResult = stopVoiceTalk(stCtrInfo);
		break;
	case enCExecItemCamer:
		bResult = execItem(stCtrInfo);
		break;
	case enCSetPointCamer:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCLightPwoer:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCStopLightPwoer:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCWiperPwoer:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCWiperLightPwoer:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCTiltUp:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCTiltDown:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCPanLeft:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCPanRight:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCTiltUpStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCTiltDownStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCPanLeftStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enCPanRightStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	//wxy++
	case enZoomAdd:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enZoomAddStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enZoomSubtract:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enZoomSubtractStop:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enSetMode:
		bResult = setMode(stCtrInfo);
		break;
	case enSetPresetArea:
		bResult = setPresetArea(stCtrInfo);
		break;
	case enRunToPrestNo:
		bResult = ptzControlOther(stCtrInfo);
		break;
	case enStartVoiceForward:
		bResult = startVoiceForward(stCtrInfo);
		break;
	case enEndVoiceForward:
		bResult = endVoiceForward(stCtrInfo);
		break;
	case enBroadcastAudio:
		bResult = broadcastAudio(stCtrInfo);
		break;
	default:
		bResult = true;
		break;
	}
	cCtrReData.sCtrId = stCtrInfo.m_sCtrId;
	cCtrReData.nCtrDevType = stCtrInfo.m_nCtrDevType;
	cCtrReData.nSubCtrDevType = stCtrInfo.m_nSubCtrDevType;
	cCtrReData.nResult = bResult;
	cCtrReData.sReDesc = stCtrInfo.m_sReData;
	if (stCtrInfo.m_bIsLog)
	{
		emit sign_ExecResult(cCtrReData);
	}
	return bResult;
}

bool CCamerCtrMange::login(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->login(sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::realPlay(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	if (stCtrInfo.m_hHwnd == NULL)
	{
		bResult = m_pCamerSdkOper->realPlay(stCtrInfo.m_nSubCtrDevType, sReInfo);
	}
	else
	{
		//for (int i = 0; i < 10000000; i++)
		//{
		//	bResult = m_pCamerSdkOper->realPlay(stCtrInfo.m_nSubCtrDevType, stCtrInfo.m_hHwnd, stCtrInfo.m_pLabel, sReInfo);
		//	//bResult = m_pCamerSdkOper->stopRealPlay(stCtrInfo.m_hHwnd, sReInfo);
		//	QThread::msleep(500);
		//}

		if (stCtrInfo.m_pLabel != nullptr)
		{
			bResult = m_pCamerSdkOper->realPlay(stCtrInfo.m_nSubCtrDevType, stCtrInfo.m_hHwnd, stCtrInfo.m_pLabel, sReInfo);
		}
		else
		{
			bResult = false;
		}
		
	}
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::stopRealPlay(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	if (stCtrInfo.m_hHwnd == NULL)
	{
		bResult = m_pCamerSdkOper->stopRealPlay(stCtrInfo.m_nSubCtrDevType, sReInfo);
	}
	else
	{
		bResult = m_pCamerSdkOper->stopRealPlay(stCtrInfo.m_hHwnd, sReInfo);
	}
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::ptzPresetOther(SCtrInfo stCtrInfo)
{
	return false;
}

bool CCamerCtrMange::capture(SCtrInfo &stCtrInfo)//Modifywxy 改成引用
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->capture(stCtrInfo.m_nSubCtrDevType, stCtrInfo.m_sImgUrl, sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	stCtrInfo.m_sReData = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::ptzControlOther(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	switch (stCtrInfo.m_nCtrCmd)
	{
	case enCLightPwoer:
		bResult = m_pCamerSdkOper->ptzControlOther(LIGHT_PWRON, 0, true, sReInfo);
		break;
	case enCStopLightPwoer:
		bResult = m_pCamerSdkOper->ptzControlOther(LIGHT_PWRON, 0, false, sReInfo);
		break;
	case enCWiperPwoer:
		bResult = m_pCamerSdkOper->ptzControlOther(WIPER_PWRON, 0, true, sReInfo);
		break;
	case enCWiperLightPwoer:
		bResult = m_pCamerSdkOper->ptzControlOther(WIPER_PWRON, 0, false, sReInfo);
		break;
	case enCTiltUp:
		bResult = m_pCamerSdkOper->ptzControlOther(TILT_UP, 3, true, sReInfo);
		break;
	case enCTiltDown:
		bResult = m_pCamerSdkOper->ptzControlOther(TILT_DOWN, 3, true, sReInfo);
		break;
	case enCPanLeft:
		bResult = m_pCamerSdkOper->ptzControlOther(PAN_LEFT, 3, true, sReInfo);
		break;
	case enCPanRight:
		bResult = m_pCamerSdkOper->ptzControlOther(PAN_RIGHT, 3, true, sReInfo);
		break;
	case enCTiltUpStop:
		bResult = m_pCamerSdkOper->ptzControlOther(TILT_UP, 3, false, sReInfo);
		break;
	case enCTiltDownStop:
		bResult = m_pCamerSdkOper->ptzControlOther(TILT_DOWN, 3, false, sReInfo);
		break;
	case enCPanLeftStop:
		bResult = m_pCamerSdkOper->ptzControlOther(PAN_LEFT, 3, false, sReInfo);
		break;
	case enCPanRightStop:
		bResult = m_pCamerSdkOper->ptzControlOther(PAN_RIGHT, 3, false, sReInfo);
		break;
	case enCSetPointCamer:
		bResult = m_pCamerSdkOper->ptzPresetOther(stCtrInfo.m_nCamerAngle, SET_PRESET,sReInfo);
		break;
	//wxy++
	case enZoomAdd:
		bResult = m_pCamerSdkOper->ptzControlOther(ZOOM_IN, 0, true, sReInfo);
		break;
	case enZoomAddStop:
		bResult = m_pCamerSdkOper->ptzControlOther(ZOOM_IN, 0, false, sReInfo);
		break;
	case enZoomSubtract:
		bResult = m_pCamerSdkOper->ptzControlOther(ZOOM_OUT, 0, true, sReInfo);
		break;
	case enZoomSubtractStop:
		bResult = m_pCamerSdkOper->ptzControlOther(ZOOM_OUT, 0, false, sReInfo);
		break;
	case enRunToPrestNo:
		bResult = m_pCamerSdkOper->ptzPresetOther(stCtrInfo.m_nCamerAngle, GOTO_PRESET, sReInfo);
		break;
	default:
		bResult = false;
		break;
	}
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::recordVideo(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	if (stCtrInfo.m_hHwnd == NULL)
	{
		bResult = m_pCamerSdkOper->recordVideo(stCtrInfo.m_sVideoUrl, stCtrInfo.m_nSubCtrDevType, sReInfo);

	}
	else
	{
		bResult = m_pCamerSdkOper->recordVideo(stCtrInfo.m_sVideoUrl, stCtrInfo.m_hHwnd, sReInfo);
	}
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::stopRecordVideo(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	if (stCtrInfo.m_hHwnd == NULL)
	{
		bResult = m_pCamerSdkOper->stopRecordVideo(stCtrInfo.m_nSubCtrDevType, sReInfo);
	}
	else
	{
		bResult = m_pCamerSdkOper->stopRecordVideo(stCtrInfo.m_hHwnd, sReInfo);
	}
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;

}

bool CCamerCtrMange::startVoiceTalk(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->startVoiceTalk(stCtrInfo.m_nSubCtrDevType, sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::stopVoiceTalk(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	bResult = m_pCamerSdkOper->stopVoiceTalk(stCtrInfo.m_nSubCtrDevType, sDevExecLog.m_sDescriptionl);
	sDevExecLog.m_bExecResult = bResult;
	if (!sDevExecLog.m_bExecResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::startVoiceForward(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台对讲");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->startVoiceForward(stCtrInfo.m_nSubCtrDevType, sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::endVoiceForward(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台对讲");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->startVoiceForward(stCtrInfo.m_nSubCtrDevType, sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

bool CCamerCtrMange::broadcastAudio(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台对讲");
	QString sReInfo = "";
	bResult = m_pCamerSdkOper->broadcastAudio(stCtrInfo.m_nSubCtrDevType, sReInfo);
	sDevExecLog.m_bExecResult = bResult;
	sDevExecLog.m_sDescriptionl = sReInfo;
	if (!bResult)
	{
		sDevExecLog.m_nAlarmLevel = enDevAlarm;	
		m_pDevData->addDevExecLog(sDevExecLog);
	}	
	return bResult;
}

bool CCamerCtrMange::execItem(SCtrInfo cCtrInfo)
{
	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	QString sReInfo = "";
	QString sVideoUrl = m_pDevDataCam->m_sRecordPath+ "Video/";
	QString sImageUrl = m_pDevDataCam->m_sRecordPath + "Image/";
	CPolItemCamer cPolItemCamer = *(CPolItemCamer *)cCtrInfo.m_pPolItemCom->m_pPolItem;
	CItemResultCamera *pItemCamerResult = (CItemResultCamera *)cCtrInfo.m_pPolItemCom->m_ItemResult;
	pItemCamerResult->m_sStartTime = QDateTime::currentDateTime().toString("yyyymmdd hh:MM:ss");
	//1.如果运动到预制点失败  返回错误
	if (cPolItemCamer.m_nIsActTrip == 1)//默认是0
	{
		if (!m_pCamerSdkOper->ptzPresetOther(cPolItemCamer.m_dAngelCamer, SET_PRESET, sReInfo))
		{
			sDevExecLog.m_bExecResult = false;
			sDevExecLog.m_nAlarmLevel = enDevAlarm;
			sDevExecLog.m_sDescriptionl = sReInfo;
			m_pDevData->addDevExecLog(sDevExecLog);
			return false;
		}
	}
	//2.如果是持续任务  判断是不是采集数据起点和终点
	if (cPolItemCamer.m_nCheckType == 1)
	{
		return true;//持续检测任务暂时不录像
		if (cPolItemCamer.m_nDevTypeCode == enVoice)
		{
			return true;
		}
		//相机录像起点	开始录像
		if (cPolItemCamer.m_nCollectIndex == 0)
		{
			if (!m_pCamerSdkOper->recordVideo(sVideoUrl, cPolItemCamer.m_nDevTypeCode, sReInfo))
			{
				sDevExecLog.m_bExecResult = false;
				sDevExecLog.m_sDescriptionl = sReInfo;
				sDevExecLog.m_nAlarmLevel = enDevAlarm;
				m_pDevData->addDevExecLog(sDevExecLog);
				return false;
			}
			pItemCamerResult->m_sIRUrl = sVideoUrl;//原始图片地址
			//pItemCamerResult->m_sHttpUrl = CPublicData::instance().m_sHttpUrl + sVideoUrl.remove(m_pDevDataCam->m_sRecordPath);
		}
		//相机录像终点  停止录像
		if (cPolItemCamer.m_nCollectIndex == 1)
		{
			if (!m_pCamerSdkOper->stopRecordVideo(cPolItemCamer.m_nDevTypeCode, sReInfo));
			{
				sDevExecLog.m_bExecResult = false;
				sDevExecLog.m_nAlarmLevel = enDevAlarm;
				sDevExecLog.m_sDescriptionl = sReInfo;
				m_pDevData->addDevExecLog(sDevExecLog);
				return false;
			}
		}
		return true;
	}
	else
	{
		//拍照
		if (cPolItemCamer.m_nTackPicture == 1)
		{
			if (!m_pCamerSdkOper->capture(cPolItemCamer.m_nDevTypeCode, sImageUrl, sReInfo))
			{
				sDevExecLog.m_bExecResult = false;
				sDevExecLog.m_sDescriptionl = sReInfo;
				sDevExecLog.m_nAlarmLevel = enDevAlarm;
				m_pDevData->addDevExecLog(sDevExecLog);
				return false;
			}
		}
		pItemCamerResult->m_dActionTime = QDateTime::currentDateTime();                        //执行时间
		sDevExecLog.m_sDescriptionl = sReInfo;
		pItemCamerResult->m_sIRUrl = sImageUrl;//原始图片地址
		pItemCamerResult->m_sHttpUrl = CPublicData::instance().m_sHttpUrl + sImageUrl.remove(m_pDevDataCam->m_sRecordPath);
		m_pDevData->addDevExecLog(sDevExecLog);
		return true;
	}
}

//设置模式
bool CCamerCtrMange::setMode(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	LONG lLoginID = m_pDevDataCam->m_sStruDeviceInfo.lLoginID;
	QString sErrMsg = "";

	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	bResult = m_pCamerSdkOper->setCameraMode(lLoginID, stCtrInfo.m_enModeType, sErrMsg);
	sDevExecLog.m_bExecResult = bResult;
	if (!sDevExecLog.m_bExecResult)
	{
		sDevExecLog.m_sDescriptionl = sErrMsg;
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	else
	{
		sDevExecLog.m_sDescriptionl = A2T("设置相机模式成功!");
	}

	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

//设置预置点区域
bool CCamerCtrMange::setPresetArea(SCtrInfo stCtrInfo)
{
	bool bResult = true;
	LONG lLoginID = m_pDevDataCam->m_sStruDeviceInfo.lLoginID;
	QString sErrMsg = "";

	SDevExecLog sDevExecLog;
	sDevExecLog.m_sDevName = A2T("云台");
	bResult = m_pCamerSdkOper->setPresetArea(lLoginID, stCtrInfo.m_stPersetAreaParam,stCtrInfo.m_stPersetAreaRect, sErrMsg);
	sDevExecLog.m_bExecResult = bResult;
	if (!sDevExecLog.m_bExecResult)
	{
		sDevExecLog.m_sDescriptionl = sErrMsg;
		sDevExecLog.m_nAlarmLevel = enDevAlarm;
	}
	else
	{
		sDevExecLog.m_sDescriptionl = A2T("设置预置点区域成功!");
	}

	m_pDevData->addDevExecLog(sDevExecLog);
	return bResult;
}

void CCamerCtrMange::slot_ThreadWork()
{
	m_bhread = true;
	while (m_bhread)
	{
		m_pMutex->lock();
		m_pCamerSdkOper->setRollerNum(m_pDevDataCam->m_nRollerNum, m_pDevDataCam->m_nBelogn, m_pDevDataCam->m_sRollerDesc);
		m_pCamerSdkOper->setCorrectData(m_pDevDataCam->m_dLeftRectifyValue, m_pDevDataCam->m_dRightRectifyValue,m_pDevDataCam->m_nRectifySetValue,m_pDevDataCam->m_nRectifySetValueTwo,m_pDevDataCam->m_BeltEdgePf1, m_pDevDataCam->m_BeltEdgePf2,
			m_pDevDataCam->m_BeltEdgePf3, m_pDevDataCam->m_BeltEdgePf4, m_pDevDataCam->m_nIsHaveBeltState, m_pDevDataCam->m_bBeltState, m_pDevDataCam->m_nDrawType);
		if (m_vecCtrQueue.size() > 0)
		{
			SCtrInfo stCtrInfo = m_vecCtrQueue[0];
			m_vecCtrQueue.remove(0);
			m_pMutex->unlock();
			ctrDeviceMy(stCtrInfo);

		}
		else
		{
			m_pMutex->unlock();
		}		
		QEventLoop loop;
		QTimer::singleShot(200, &loop, SLOT(quit()));
		loop.exec();
	}
}
